<?php 
defined('IN_TS') or die('Access Denied.');
//喜欢课程
switch($ts){

	case "":
		break;
		
	case "do":
	
		$userid = intval($TS_USER['userid']);
		if($userid == 0){
			echo 0;exit;
		}
		
		$studyid = $_POST['studyid'];
		
		$isLove = $new['study']->findCount('study_love',array(
			'userid'=>$userid,
			'studyid'=>$studyid,
		));
		
		if($isLove > 0){
			echo 1;exit;
		}
		
		$new['study']->create('study_love',array(
			'userid'=>$userid,
			'studyid'=>$studyid,
			'addtime'=>time(),
		));
		
		//统计喜欢数
		$count_love = $new['study']->findCount('study_love',array(
			'studyid'=>$studyid,
		));
		
		$new['study']->update('study',array(
			'studyid'=>$studyid,
		),array(
			'count_love'=>$count_love,
		));
		
		echo 2;exit;
	
		break;
		
	case "cancel":
	
		$userid = intval($TS_USER['userid']);
		if($userid == 0){
			echo 0;exit;
		}
		
		$studyid = $_POST['studyid'];
		
		$isLove = $new['study']->findCount('study_love',array(
			'userid'=>$userid,
			'studyid'=>$studyid,
		));
		
		if($isLove == 0){
			echo 1;exit;
		}
		
		$new['study']->delete('study_love',array(
			'userid'=>$userid,
			'studyid'=>$studyid,
		));
		
		//统计喜欢数
		$count_love = $new['study']->findCount('study_love',array(
			'studyid'=>$studyid,
		));
		
		$new['study']->update('study',array(
			'studyid'=>$studyid,
		),array(
			'count_love'=>$count_love,
		));
		
		echo 2;exit;
	
		break;


}